import request from '@/config/axios'
import { facilityDataType, recordDataType } from '@/views/Firewarning/types'

// 监测预警设施列表
export const fireMapGet = () => {
  return request.get({
    url: `/1.1/classes/FireWarning`
  })
}

interface WhereType {
  name: { $regex: string; $options: 'i' }
  // parkName: { $regex: string; $options: "i" };
}

export const fireFacilityGet = (
  page: number = 1,
  size: number = 10,
  condition?: {
    name: string
    // parkName: string
  }
) => {
  const skip = (page - 1) * size
  const where: WhereType = {} as WhereType
  //携带岗位名称
  if (condition && condition.name) {
    where.name = { $regex: condition.name, $options: 'i' }
    // console.log("adaddasd");
  }

  const query = JSON.stringify(where)
  return request.get({
    url: `/1.1/classes/FireWarning?where=${query}&limit=${size}&count=${1}&skip=${skip}`
    // params: {
    //     limit: size,
    //     count: 1, //开启对象计数（数据表总条数）
    //     skip,
    // }
  })
}

// 监测预警设施新增
export const fireFacilityPost = (data) => {
  return request.post({ url: '/1.1/classes/FireWarning', data })
}

// 监测预警设施编辑角色
export const fireFacilityPut = (id: string, data: Omit<facilityDataType, 'objectId'>) => {
  // 发起put请求
  return request.put({ url: `/1.1/classes/FireWarning/${id}`, data })
}

// 监测预警设施删除
export const fireFacilityDel = (id: string) => {
  // 发起delete请求
  return request.delete({ url: `/1.1/classes/FireWarning/${id}` })
}

// 地图组件渲染
export const fireRecordMapGet = () => {
  return request.get({ url: '/1.1/classes/FireWarning' })
}

// 火灾记录列表渲染
// export const fireRecordGet = () => {
//     return request.get({
//         url: `/1.1/classes/FireRecord`
//     })
// }
interface WhereType {
  position: { $regex: string; $options: 'i' }
  // parkName: { $regex: string; $options: "i" };
}

export const fireRecordGet = (
  page: number = 1,
  size: number = 10,
  condition?: {
    position: string
    // parkName: string
  }
) => {
  const skip = (page - 1) * size
  const where: WhereType = {} as WhereType
  //携带岗位名称
  if (condition && condition.position) {
    where.position = { $regex: condition.position, $options: 'i' }
    // console.log("adaddasd");
  }

  const query = JSON.stringify(where)
  return request.get({
    url: `/1.1/classes/FireRecord?where=${query}&limit=${size}&count=${1}&skip=${skip}`
    // params: {
    //     limit: size,
    //     count: 1, //开启对象计数（数据表总条数）
    //     skip,
    // }
  })
}

// 火灾记录修改
export const fireRecorPut = (id: string, data: Omit<recordDataType, 'objectId'>) => {
  // 发起put请求
  return request.put({ url: `/1.1/classes/FireRecord/${id}`, data })
}

// 火灾记录新增
export const fireRecorPost = (data) => {
  return request.post({ url: '/1.1/classes/FireRecord', data })
}

// 火灾记录删除
export const fireRecorDel = (id: string) => {
  // 发起delete请求
  return request.delete({ url: `/1.1/classes/FireRecord/${id}` })
}
